<!DOCTYPE html>
<html>
<head>
    <title>{$platform.name}</title>
    <link href="/static/css/framework-font.css" rel="stylesheet"/>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>

    <script src="/static/js/jquery.cookie.js"></script>
    <link href="/static/css/framework-theme.css" rel="stylesheet"/>
    <script src="/static/js/framework-ui.js"></script>
    <script src="/static/js/framework-clientdata.js"></script>

    <!--弹框js-->
    <script src="/static/js/yii.js"></script>

    <!--引用layui弹框插件-->
    <script src="/static/layui/layui.all.js"></script>
    <script src="/static/layui/layui.js"></script>
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/lay/modules/layer.js"></script>


    <!--    配置select多选相关-->
<!--    <script src="/static/layui/dist/xm-select.js"></script>-->


        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
    <link href="/static/css/default/public.css" rel="stylesheet"/>
    {/if}
    {/if}
</head>
<body>
<style>
    html, body{background-color:#FFF!important;}
    .modal-body{background-color:#fff;padding:15px}
    .page-header{margin-top:15px!important;}
    .add_button{border-top:1px solid #eee;padding-top:15px;}
</style>

<div class="modal-body">


    <div class="page-header">
        <h3>添加代理商</h3>
    </div>

    <form class="form-horizontal layui-form">

        <div class="form-group">
            <label class="col-sm-1 control-label">*账号:</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" name="name" placeholder="账号" >
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label">*密码:</label>
            <div class="col-sm-8">
                <input type="password" class="form-control" name="password" placeholder="密码" >
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label">*确认密码:</label>
            <div class="col-sm-8">
                <input type="password" class="form-control" name="password1" placeholder="确认密码" >
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label">公司名称:</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" name="company" placeholder="公司名称" >
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label">公司简介:</label>
            <div class="col-sm-8">
                <textarea  name="desc"  placeholder="请输入公司简介" class="layui-textarea" lay-verify="content"></textarea>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label">法人:</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" name="legal_person" placeholder="法人" >
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label">组织机构代码:</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" name="institution_code" placeholder="组织机构代码" >
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label">官方网站:</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" name="web" placeholder="官方网站" >
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label">手机号码:</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" name="phone" placeholder="手机号码" >
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label">代理城市:</label>
            <div class="col-sm-8">
                <div id="test12" class="demo-tree-more"></div>
            </div>
        </div>


<!--        <div class="form-group">-->
<!--            <label  class="col-sm-1 control-label">*状态:</label>-->
<!--            <div class="col-sm-8">-->
<!--                <input type="radio" name="status" value="1" title="启用" checked="">-->
<!--                <input type="radio" name="status" value="2" title="禁用">-->
<!--            </div>-->
<!--        </div>-->


    </form>
</div>
<div class="add_button">

    <div class="form-group">
        <label  class="col-sm-1 control-label"></label>
        <div class="col-sm-8">
            <a type="button" class="layui-btn layui-btn-primary" href="{:URL('admin/agent/index')}" >取消</a>
            <button type="button" class="layui-btn" id="newsave" >保存</button>
        </div>
    </div>
</div>


<script>

    layui.use(['form','layedit','tree','util'], function() {
        var form = layui.form
            , layer = layui.layer;
        var layedit = layui.layedit;
        var  tree = layui.tree;
        var util = layui.util;

        $("#newsave").click(function () {
            var checkedData = tree.getChecked('demoId1'); //获取选中节点的数据
            var data = $("form").serialize();

            //data.push('checkedData',checkedData);
            data = data+"&checkedData="+JSON.stringify(checkedData);

            $.ajax({
                type:'post',
                url:"{:URL('admin/agent/addAgent')}",
                data:data,
                dataType:'JSON',
                success:function (res) {
                    if(res.code!=0){
                        layer.alert(res.msg);
                    }else{
                        window.location.href = "{:URL('admin/agent/index')}";
                    }
                },
                error:function (res) {
                    
                }
            });

        })


        //获取数据
        $.ajax({
            type:'post',
            url:"{:URL('common/Common/region')}",
            success:function(data){
                //data1 = JSON.parse()
                data = data.data;
                // console.log('data:',data);
                //基本演示
                tree.render({
                    elem: '#test12'
                    ,data: data
                    ,showCheckbox: true  //是否显示复选框
                    ,id: 'demoId1'
                    ,isJump: true //是否允许点击节点时弹出新窗口跳转
                    ,click: function(obj){
                        // var data = obj.data;  //获取当前点击的节点数据
                        // layer.msg('状态：'+ obj.state + '<br>节点数据：' + JSON.stringify(data));
                    }
                });
            }
        })

        util.event('lay-demo', {
            getChecked: function(othis){
                var checkedData = tree.getChecked('demoId1'); //获取选中节点的数据
                layer.alert(JSON.stringify(checkedData), {shade:0});
                // console.log(checkedData);
            }
            ,setChecked: function(){
                tree.setChecked('demoId1', [12, 16]); //勾选指定节点
            }
            ,reload: function(){
                //重载实例
                tree.reload('demoId1', {

                });

            }
        });


        layui.form.render('select');
        form.render();


    });
</script>

</body>
</html>